//
//  YYTBanner.swift
//  Yuyuto
//
//  Created by Arthur on 2017/6/20.
//  Copyright © 2017年. All rights reserved.
//

import UIKit
import YYKit

let DFTimeInterval = 5.0          //全局的时间间隔

class DFBannerView: UIView, SDCycleScrollViewDelegate {
    
    weak var delegate: DFBannerViewDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(cycleScrollView)
        cycleScrollView.frame = frame
        cycleScrollView.snp.makeConstraints { (make) in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(0, 0, 0, 0))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public func update(imageURLStringGroup: Array<String>) {
        cycleScrollView.imageURLStringsGroup = imageURLStringGroup
    }
    
   //MARK: - SDCycleScrollViewDelegate
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
        delegate?.dfBannerView?(self, didSelectItemAt: index)
    }
    
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didScrollTo index: Int) {
        delegate?.dfBannerView?(self, didScrollTo: index)
    }

    
    lazy var cycleScrollView: SDCycleScrollView = {
        [unowned self] in
        let temp = SDCycleScrollView.init()
        temp.bannerImageViewContentMode = .scaleAspectFill;
        temp.autoScrollTimeInterval = 5.0;
        temp.delegate = self
        return temp
    }()
}

@objc protocol DFBannerViewDelegate {
    /**
     *  点击图片的代理方法
     *
     *  @para  currentIndxe 当前点击图片的下标
     */
    @objc optional func dfBannerView(_ bannerView: DFBannerView, didSelectItemAt index: Int)
    
    @objc optional func dfBannerView(_ bannerView: DFBannerView, didScrollTo index: Int)
}
